<?php

namespace App\Traits;

use DB;
trait FormTrait
{

    public function techDeviceFormData($request)
    {
        $formMainInfo = [
            'company_name' => $request->input('company_name'),
            'company_desc' => $request->input('company_desc'),
            'user_name' => $request->input('user_name'),
            'user_phone' => $request->input('user_phone'),
        ];
        $listData = $request->input('tech_device_list');

        if (count($listData) > 0) {
            $id = DB::table('form_info')->insertGetId($formMainInfo);
            foreach ($listData as $key => $value) {
                $listInfo = [
                    'form_id' => $id,
                    'tech_device_type' => $value['tech_device_type'],
                    'tech_device_name' => $value['tech_device_name'],
                    'tech_device_brand' => $value['tech_device_brand'],
                    'tech_device_bool_patent' => $value['tech_device_bool_patent'],
                    'tech_device_price' => $value['tech_device_price'],
                    'tech_device_fix_years' => $value['tech_device_fix_years'],
                    'tech_device_point' => $value['tech_device_point'],
                    'tech_device_case' => $value['tech_device_case'],
                ];
                DB::table('form_list_info')->insert($listInfo);
            }
            return true;
        }
    }

    public function workerFormData($request)
    {
        $formMainInfo = [
            'company_name' => $request->input('company_name'),
            'company_desc' => $request->input('company_desc'),
            'user_name' => $request->input('user_name'),
            'user_phone' => $request->input('user_phone'),
        ];
        $id = DB::table('form_info')->insertGetId($formMainInfo);
        $listInfo = [
            'form_id' => $id,
            'tech_device_price' => $request->input('tech_device_price'),
            'fix_per_time' => $request->input('fix_per_time'),
            'tech_device_fix_years' => $request->input('tech_device_fix_years'),
            'tech_device_case' => $request->input('tech_device_case'),
        ];
        DB::table('form_list_info')->insert($listInfo);
        return true;
    }

    public function boaterFormData($request)
    {
        $formMainInfo = [
            'company_name' => $request->input('company_name'),
            'company_desc' => $request->input('company_desc'),
            'user_name' => $request->input('user_name'),
            'user_phone' => $request->input('user_phone'),
        ];
        $listData = $request->input('tech_device_list');
        if (count($listData) > 0) {
            $id = DB::table('form_info')->insertGetId($formMainInfo);
            foreach ($listData as $key => $value) {
                $listInfo = [
                    'form_id' => $id,
                    'tech_device_type' => $value['tech_device_type'],
                    'tech_device_name' => $value['tech_device_name'],
                    'tech_device_brand' => $value['tech_device_brand'],
                    'tech_device_bool_patent' => $value['tech_device_bool_patent'],
                    'tech_device_fix_years' => $value['tech_device_fix_years'],
                    'tech_content' => $value['tech_content'],
                    'tech_main_point' => $value['tech_main_point'],
                    'tech_advantage' => $value['tech_advantage'],
                    'tech_used_range' => $value['tech_used_range'],
                    'tech_device_case' => $value['tech_device_case'],
                    'tech_vista' => $value['tech_vista'],
                ];
                DB::table('form_list_info')->insert($listInfo);
            }
            return true;
        }
    }

}
